#ifndef __DS18B20_H__
#define __DS18B20_H__

#include "common.h"
#include "errno.h"

//DS18B20??  
typedef enum   
{  
    SEARCH_ROM          =   0xf0,   //??ROM??  
    READ_ROM            =   0x33,   //??ROM??  
    MATH_ROM            =   0x55,   //??ROM??  
    SKIP_ROM            =   0xcc,   //??ROM??  
    ALARM_SEARCH        =   0xec,   //??????  
    CONVERT_T           =   0x44,   //??????  
    WRITE_SCRATCHPAD    =   0x4e,   //??????  
    READ_SCRATCHPAD     =   0xbe,   //???????  
    COPY_SCRATCHPAD     =   0x48,   //???????  
    RECALL_E2           =   0xb8,   //??EEPROM??  
    READ_POWER_SUPPLY   =   0xb4,   //????????  
} DS18B20_CMD_t;  


//DS18B20 ROM??  
typedef struct  
{  
    uint8_t  DS18B20_CODE;   //DS18B20?????:0x19  
    uint8_t  SN_1;           //????1??  
    uint8_t  SN_2;           //????2??  
    uint8_t  SN_3;           //????3??  
    uint8_t  SN_4;           //????4??  
    uint8_t  SN_5;           //????5??  
    uint8_t  SN_6;           //????6??  
    uint8_t  crc8;           //CRC8???     
} DS18B20_ROM_CODE_t;     


extern uint8_t g_ds18b20_data[];
const uint8_t g_ds_rom[][8];
extern int g_ds18b20_temp;
extern uint8_t g_ds18b20_time_cnt;
extern uint8_t g_ds18b20_rom[];

//������ʱ���
//key_time_count()�ŵ���ʱ���жϷ��������
#define ds18b20_time_count() do{g_ds18b20_time_cnt++;}while(0)  //���趨ʱ���ж�Ϊ10ms����һ���ж�


int ds18b20_rst(void); //复位DS18B20函数
int ds18b20_get_rom(uint8_t* p_temp);

int ds18b20_get_temp(long int* p_temp);
int ds18b20_get_temp_from_rom(uint8_t (*p_rom)[8],long int* p_temp);

void user_ds18b20(void);

#endif